home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 4 / Precision Software Applications Silver Collection Volume 4 (1993).iso / stats / chadyn.exe / Y.C < prev    next >
Text File  |  1988-12-14  |  14KB  |  516 lines

  1. /******************* (C) 1986,7,8 by JAMES A. YORKE **************************/
  2. /***********************************  Y.C  ***********************************/
  3.  
  4. /* The program DYNAMICS.C is for plotting various maps on the screen(crt) 
  5.    and printing contents of p[][] on printer in a highly interactive manner.
  6.    To compile it, Y.C must be compiled and linked to several other files;
  7.     the list of files to be linked is in file YS;
  8.                 James Yorke
  9.                     10/11/87               
  10. *******************************  Routines in Y.C  *****************************
  11.     main(argc, argv)
  12.     Trajectory()
  13.     plotSomething()
  14.     plotXX(),plotXY(),plotRY(),plotXR(),plotAll()
  15.     caseT()
  16.     circleImage(action,ddot)
  17.     checkFreq()
  18.     setTDTime() called using command "TDTime" 
  19.     setRunTime() called using command "runtime" 
  20.     initTime()
  21.     printTimes(fff) for DumpData() runtime and tdtime -- see YDISK.C
  22. ******************************************************************************/
  23.  
  24. /* Define all external symbols here. */
  25. #define INITIAL(x) = x
  26. #define EXTERN            
  27. #include "yinclud.h"
  28.  
  29. char    DiskFileName[20];    /* for saving pictures on disk */
  30.  
  31. main(argc, argv)
  32. int     argc;
  33. char   *argv[];
  34. {
  35.     char    CodeName[MAXCHAR+1];
  36.  
  37.     OpenFiles(argc, argv);    /* in YFetch.c, opens files, displays title
  38.                    page, sets video mode */
  39.  
  40.     for(;;) {
  41.         PickMap();    /* in YPICKMAP.C */
  42.  
  43.         select_items(CodeName);/* in YCOM.C */
  44.     }
  45. }
  46. /* the following are in ydefines.h:
  47. #define PLOTXY 0
  48. #define PLOTALL 2
  49. #define PLOTXX 4
  50. #define PLOTRY 6
  51. #define PLOTXR 8
  52. #define PLOTCIRC 100           */
  53.  
  54. extern long     bifPreIterates;    /* declared in ybifrcat.c */
  55. static double   Old;        /* for plotXX() */
  56. long     initialdot;
  57. static double   delrho;
  58. static long     modulo;        /* for plotXR and plotRY */
  59. static long     dotMOD;
  60. static int      numRhos;
  61.  
  62.  
  63. Trajectory() {            /* process for iterating; refreshFlag is set
  64.                    using the command "cont"; when = YES, dot
  65.                    does not have to start from 0 */
  66. #ifndef MAINFRAME
  67.     int     ChkKeyStatus();
  68. #endif
  69.     int     level0 = level;
  70.     int     i;
  71.     int     checkFreq();
  72.     int     null();    /* needed for pointer that is not being used */
  73.     long    savedots = dots;
  74.     int     minimum = ((eqn1 < dim) ? eqn1 : dim);
  75.  
  76.     scr_rowcol(0, 0);
  77.     if(TDFreq > 0)
  78.         PRINT
  79.     "WARNING: picture is stored to disk every %ld iterates.\n", TDFreq);
  80.  
  81.     if(dot > 0 && dot < dots && refreshFlag == YES)
  82.                 /* dot >0 is most likely to occur when using
  83.                    command "cont" */
  84.         ;
  85.     else {
  86.         dot = -preiter;
  87.     }
  88.     dotAtTime0 = dot;
  89.     initialdot = dot;
  90.  
  91.     refreshFlag = NO;
  92.     stoplines();        /* stop drawing connected lines */
  93.     if(taskFlag < 100) {    /* it can be set >= 100 for special tasks like
  94.                    drawing circles */
  95.         if(X_coord >= 0 && Y_coord >= 0) {
  96.             if(X_coord != Y_coord) {
  97.                 if(allSSFlag == NO)
  98.                     taskFlag = PLOTXY;
  99.                 else
  100.                     taskFlag = PLOTALL;
  101.             }
  102.             else
  103.                 if(X_coord == Y_coord)
  104.                     taskFlag = PLOTXX;
  105.         }
  106.         else
  107.             if(X_coord == -1) {
  108.                 taskFlag = PLOTRY;
  109.                 numRhos = corecols;
  110.                 setdots(numRhos);
  111.                 /* defines dots; in YBIFRCAT.C */
  112.                 modulo = dots / numRhos;
  113.                 /* = the number of dots per rho value */
  114.                 delrho = (X_upper - X_lower) / numRhos;
  115.             }
  116.             else
  117.                 if(Y_coord == -1) {
  118.                     taskFlag = PLOTXR;
  119.                     numRhos = corerows * 8;
  120.                     setdots(numRhos);
  121.                 /* defines dots; in YBIFRCAT.C */
  122.                     modulo = dots / numRhos;
  123.                 /* = the number of dots per rho value */
  124.                     delrho = (Y_upper - Y_lower) / numRhos;
  125.                 }
  126.     }
  127.  
  128. #ifndef MAINFRAME
  129.     if(ChkKeyStatus() != 0 || cycle > 0)
  130.         Interrupt();
  131. #endif
  132.     initTime();        /* see below */
  133.     for(; level == level0 && dot < dots; dot++) {
  134.         if(timeFlag == YES || TDFreq > 0)
  135.             if(checkFreq() == YES) 
  136.             {    /* means terminate; checkFreq also handles
  137.                    occasional transmissions of picture to disk 
  138.                 */
  139.                 PRINT "process termination: OUT OF TIME \n");
  140.                 level = level0 - 1;
  141.                 continue;
  142.             }
  143.  
  144. #ifndef MAINFRAME
  145.         if(ChkKeyStatus () != 0 || cycle > 0)
  146.             Interrupt();
  147. #endif
  148. /*if(printer == 3)PRINT "taskFlag = %d\n",taskFlag);*/
  149.  
  150.         if(taskFlag == PLOTXY) {
  151.             plotX = *Xplot[ScrnSec];
  152.             plotY = *Yplot[ScrnSec];
  153.             if(dot >= 0)
  154.                 (*plotPointer) (plotX, plotY);
  155.             (*iteratee) ();
  156.         }
  157.         else
  158.             plotSomething(1);
  159.  
  160.         if(printer >= 4)
  161.             if((printer == 4) || (printer == 5)) {
  162.                 /* print trajectory values every iterate if ==
  163.                    5 */
  164.                 fprintf(StPrint, "#%ld  ", dot);
  165.                 for(i = 0; i < minimum; i++)
  166.                     fprintf(StPrint, "y[%d]=%lf  ", i, y[i]);
  167.                 fprintf(StPrint, "\n");
  168.                 if(printer == 4)
  169.                     printer = 2;
  170.             }
  171.     }            /* end for(;... */
  172.     dots = savedots;    /* restore value in case it has been changed */
  173.     if(level <= 2)
  174.         scr_clr();    /* in desmets pcio.a */
  175.     scr_rowcol(0, 0);
  176. }
  177.  
  178.  
  179. plotSomething(action)        /* action = 0 means do not iterate process,
  180.                    just plot */
  181. int     action;
  182. {
  183.     switch(taskFlag)  {
  184.     case PLOTXY:
  185.         plotXY(action);
  186.         break;
  187.     case PLOTALL:
  188.         plotALL(action);
  189.         break;
  190.     case PLOTXX:
  191.         plotXX(action);
  192.         break;
  193.     case PLOTRY:
  194.         plotRY(action);
  195.         break;
  196.     case PLOTXR:
  197.         plotXR(action);
  198.         break;
  199.     case PLOTCIRC:
  200.         circleImage(action, (double) dot);
  201.         break;
  202.     }
  203.     return;
  204. }
  205.  
  206. plotXX(action)            /* Old is a static double */
  207. int     action;
  208. {
  209.     plotX = Old;
  210.     plotY = y[X_coord];
  211.     if(dot >= 1)
  212.         (*plotPointer) (plotX, plotY);
  213.     Old = y[X_coord];
  214.     if(action > 0)
  215.         (*iteratee) ();
  216. }
  217.  
  218. plotXY(action)
  219. int     action;
  220. {
  221.     plotX = *Xplot[ScrnSec];
  222.     plotY = *Yplot[ScrnSec];
  223.     if(dot >= 0)
  224.         (*plotPointer) (plotX, plotY);
  225.     if(action > 0)
  226.         (*iteratee) ();
  227. }
  228.  
  229. circleImage(action, ddot)
  230. int     action;
  231. double  ddot;
  232. {
  233.     int     i;
  234.     double  rot;
  235.     int     levelc = level;
  236.  
  237.     rot = ddot * twopi * (sqrt(5.) - 3.) / 2;
  238.     setequal(0, 1, eqn1);    /* initialize y */
  239.     plotX = *Xplot[ScrnSec] += rad_attr * cos(rot);
  240.     plotY = *Yplot[ScrnSec] += rad_attr * sin(rot);
  241.     (*plotPointer) (plotX, plotY);
  242.     for(i = 0; i < images && levelc == level; i++) {
  243.         if(action > 0)
  244.             (*iteratee) ();
  245.         plotX = *Xplot[ScrnSec];
  246.         plotY = *Yplot[ScrnSec];
  247.         (*plotPointer) (plotX, plotY);
  248.     }
  249. }
  250.  
  251. plotALL(action)        /* cannot use 'k' to plot crosses in every
  252.                    screen */
  253. int     action;
  254. {
  255.     int     ss;
  256.  
  257.     turnoff(BIGCROSS);
  258.     cross0flag = OFF;
  259.     for(ss = 1; ss < 5; ss++)
  260.         if(xScrPix[ss] != -9999.) {
  261.             X_lower = X_Lo[ss];/* used by plot() */
  262.             X_upper = X_Up[ss];
  263.             Y_upper = Y_Up[ss];
  264.             Y_lower = Y_Lo[ss];
  265.             ScrnSec = ss;
  266.             plotX = *Xplot[ss];
  267.             plotY = *Yplot[ss];
  268.             (*plotPointer) (plotX, plotY);
  269.         }
  270.     if(action > 0)
  271.         (*iteratee) ();
  272. }
  273.  
  274. plotXR(action)
  275. int     action;
  276. {
  277.  /* We are going to compute for numRhos different values of rho; if InitFlag=ON
  278.     we initialize at the beginning of eah rho; notice modulo = dots/numRhos is
  279.     a(long) integer, the number of potential dots for each rho; we increment
  280.     rho by 1/numRhos of the X_range or y range every modulo dots; if preiter is
  281.     positive, the the first preiter(out of modulo potential dots) will not be
  282.     plotted; we do this by computing dotMOD = dot mod modulo. */
  283.  
  284.     dotMOD = dot % modulo;    /* =dot MOD modulo(integer mod) */
  285.     if(dotMOD == 0) {
  286.         if(InitFlag == ON)
  287.             setequal(0, 1, dim);/* initialize y */
  288.         rho = rho + delrho;
  289.         if(printer > 2) {
  290.             erase_line();
  291.             PRINT "dot=%ld;rho=%lf; rho value # %ld \r"
  292.                 ,dot, rho, dot / modulo);
  293.         }
  294.     }
  295.     else {
  296.         if(dotMOD >= bifPreIterates) {
  297.                 /* this means we preiterate for each new rho
  298.                    before plotting */
  299.             plotX = *Xplot[ScrnSec];
  300.             plotY = *Yplot[ScrnSec];
  301.             (*plotPointer) (plotX, plotY);
  302.         }
  303.     }
  304.     if(action > 0)
  305.         (*iteratee) ();
  306. }
  307.  
  308. plotRY(action)
  309. int     action;
  310. {
  311.  /* We are going to compute for numRhos different values of rho; if InitFlag=ON
  312.     we initialize at the beginning of eah rho; notice modulo = dots/numRhos is
  313.     a(long) integer, the number of potential dots for each rho; we increment
  314.     rho by 1/numRhos of the X_range or y range every modulo dots; if preiter is
  315.     positive, the the first preiter(out of modulo potential dots) will not be
  316.     plotted; we do this by computing dotMOD = dot mod modulo. */
  317.  
  318.     dotMOD = dot % modulo;    /* =dot MOD modulo(integer mod) */
  319.     if(dotMOD == 0) {
  320.         if(InitFlag == ON)
  321.             setequal(0, 1, dim);/* initialize y */
  322.         rho = rho + delrho;
  323.         if(printer > 2) {
  324.             erase_line();
  325.             PRINT "dot=%ld;rho=%lf; rho value # %ld \r"
  326.                 ,dot, rho, dot / modulo);
  327.         }
  328.     }
  329.     else {
  330.         if(dotMOD >= bifPreIterates) {
  331.                 /* this means we preiterate for each new rho
  332.                    before plotting */
  333.             plotX = *Xplot[ScrnSec];
  334.             plotY = *Yplot[ScrnSec];
  335.             if(dot >= 0)
  336.                 (*plotPointer) (plotX, plotY);
  337.         }
  338.     }
  339.     if(action > 0)
  340.         (*iteratee) ();
  341. }
  342.  
  343.  
  344. caseT() {            /* This routine does some house keeping before
  345.                    and after calling trajectory(); these two
  346.                    routines go together; call this one and it
  347.                    calls trajectory() */
  348.     int     level1;
  349.  
  350.     max_error = 0;
  351.  
  352.     (*init_process) ();    /* this is determined in select_map in Ymaps
  353.                    and possibly elsewhere. It is used to make
  354.                    calculations that have to be made only at
  355.                    the beginning of an iterative process. The
  356.                    calculations might depend on constants like
  357.                    C1 but not on rho(or y[]) because rho can
  358.                    be changed while the map is being iterated.
  359.                    Most often it is null(). */
  360.  
  361.     if(preiter > 0 && refreshFlag == NO)
  362.         setequal(0, 1, dim);
  363.     if(X_coord == -1)
  364.         rho = X_lower +.0000000001 * (X_upper - X_lower);
  365.     if(Y_coord == -1)
  366.         rho = Y_lower +.0000000001 * (Y_upper - Y_lower);
  367.  
  368.     level1 = ++level;
  369.     for(rho_begin = rho;
  370.             fabs(rho_begin - rho) *.9999999999 <= fabs (rho_begin - rho_final)
  371.             && (level == level1); rho = rho + rho_step) {
  372.                 /* fabs() = absolute value of a double
  373.                    precision real */
  374.         if(level == PROCESS)
  375.             boot_crt();/* prepares the screen for graphics */
  376.  
  377.  
  378.  
  379.     /* **        Beginning of routine for plotting attractor       ** */
  380.     /* **  level == KILL will terminate program          ** */
  381.  
  382.         Trajectory();
  383. #ifndef X11
  384.         if(onprint >= 1 && dot >= dots) {
  385.             pprint(onprint);
  386.                 /* this sends picture to B: disk if disk = 1 */
  387.         }
  388. #endif
  389.     }            /* rho_step end */
  390.     rho = rho - rho_step;    /* don't increment if rho would be too large */
  391.  
  392.     level = level1 - 1;
  393.     if(SCREEN)
  394.         if(level == 2)
  395.             MainMenu();
  396. }
  397.  
  398. int     checkFreq()         /* checks TDFREQ returns YES if current process
  399.                    should be stopped; time0 & lastTDTime are
  400.                    initiallized in initTime() which is called
  401.                    in Trajectory(); TDFreq, timeFlag, and
  402.                    TDTime are set to 0 when the screen is
  403.                    cleared */
  404. {
  405.     double timeofday();
  406.  
  407.     if(TDFreq > 0) {    /* if TDFreq != 0, td() to be called regularly 
  408.                 */
  409.         if(dot % TDFreq == 0) {
  410.             if(dot > initialdot && dot > 0) {
  411.                 checkTimeAndPrint();
  412.             }    /* if dot > ... */
  413.         }        /* if dot % ... */
  414.     }            /* end if(TDFreq... */
  415.  
  416.     if(timeFlag == YES) {    /* this means the timer is running for either
  417.                    termination of sending to disk or both; */
  418.         time1 = timeofday();
  419.         if(time1 < time0)/* can happen after passing midnight */
  420.             lastTDTime = time0 = time1;
  421.         if(TDTime > 0) {
  422.             if(time1 > time0 + TDTime
  423.                     && time1 > lastTDTime + TDTime) {
  424.                 lastTDTime = time1;
  425.                 td();/* = To DIsk in YPLOT */
  426.             }
  427.         }
  428.         if(runTime > 0)
  429.             if(time1 > time0 + runTime) {
  430.                 time0 = timeofday();
  431.                 /* this is reset so that lower level processes
  432.                    will also have the same amount of time */
  433.                 return(YES);
  434.             }
  435.     }
  436.     return(NO);
  437. }
  438.  
  439. checkTimeAndPrint() 
  440. {
  441.     double timeofday();
  442.     time1 = timeofday();
  443.                 /* don't send picture to disk if less than 100
  444.                    seconds has elapsed since last setting time0
  445.                    */
  446.  
  447.     if(time1 < time0) {
  448.         time0 = time1;
  449.         return;
  450.     }
  451.     if(time1 - time0 < 100.) {
  452.         scr_rowcol(10, 0);
  453.         PRINT
  454.             "            ******* ALERT **** \n");
  455.         PRINT
  456.             "WARNING: Program is set to send picture to disk in less than 100 seconds.\n");
  457.         PRINT
  458.             " ***** use TDFREQ to set frequency, or risk destoying existing picture ****\n"
  459.             );
  460.  
  461.     }
  462.     else {
  463.         td();        /* to disk in YPLOT.C */
  464.     }
  465. }
  466.  
  467. setTDTime() {            /* called using command "TDTime" */
  468.     double  minval;
  469.  
  470.     timeFlag = YES;
  471.     if(SCREEN)
  472.         PRINT "Enter a time in minutes >= 0       \n");
  473.     minval = TDTime / 60.;
  474.     minval = Entervalue(minval, CHECKSET);
  475.     if(minval >= 0)
  476.         TDTime = 60.* minval;
  477.     if(TDTime == 0 && runTime == 0)
  478.         timeFlag = NO;
  479. }
  480. setRunTime() {            /* called using command "runtime" */
  481.     double  minval;
  482.  
  483.     timeFlag = YES;
  484.     if(SCREEN)
  485.         PRINT "Enter a time in minutes >= 0       \n");
  486.     minval = runTime / 60.;
  487.     minval = Entervalue(minval, CHECKSET);
  488.     if(minval >= 0)
  489.         runTime = 60.* minval;
  490.     if(TDTime == 0 && runTime == 0)
  491.         timeFlag = NO;
  492. }
  493.  
  494. initTime() {            /* records time for later comparison */
  495.  
  496.     lastTDTime = time0 = timeofday();
  497. }
  498.  
  499. printTimes(fff)        /* for DumpData() runtime and tdtime -- see
  500.                    YDISK.C; This is handled here because the
  501.                    required variables are static, so they are
  502.                    not accessible from YDISK */
  503. FILE * fff;
  504. {
  505.  
  506.     if(TDTime > 0)
  507.         fprintf(fff,
  508.                 "TDTIME  %lf /* frequency in minutes for sending picture to disk */\n",
  509.                 TDTime / 60.);/* TDTime is in seconds */
  510.     if(runTime > 0)
  511.         fprintf(fff,
  512.                 "RUNTIME %lf /* frequency in minutes for sending picture to disk */\n",
  513.                 runTime / 60.);/* runTime is in seconds */
  514. }
  515.